<template>
  <div class="operation">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="操作员：">
        <el-select v-model="state" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.Id"
            :label="item.OperatorName"
            :value="item.Id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="起止时间：">
        <div class="block">
          <el-date-picker
            v-model="value"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="" class="el-icon-search" @click="onSubmit()"
          >查询</el-button
        >
        <!-- <el-button class="el-icon-download"  @click="exportClick()">导出为文档</el-button> -->
      </el-form-item>
    </el-form>
    <!-- 支出申请表格 -->
    <div>
      <el-table
        :header-cell-style="{ 'text-align': 'center' }"
        :cell-style="{ 'text-align': 'center' }"
        ref="multipleTable"
        :data="
          tableData.slice((currentPage - 1) * pagesize, currentPage * pagesize)
        "
        tooltip-effect="dark"
        border
        height="calc( 100vh - 220px)"
      >
        <el-table-column prop="name" type="index" label="序号" width="60">
        </el-table-column>
        <el-table-column prop="opername" label="操作员" width="150px">
        </el-table-column>
        <el-table-column prop="Operhistory" label="操作记录" width="250">
        </el-table-column>
        <el-table-column prop="Opertime" label="操作时间" width="200">
        </el-table-column>
        <!-- <el-table-column prop="name" label="操作" width="200">
        </el-table-column> -->
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 50, 100, 200]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.tableData.length"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { API_GET_OPERATOR_LIST } from "../../api/system";
import { API_GET_USER_ADMIN } from "../../api/adjustment";
export default {
  name: "",
  data() {
    return {
      msg: "操作历史查询",
      state: "", // 操作员
      value: [], // 起止时间
      tableData: [],
      pagesize: 10, // 每页的数据条数
      currentPage: 1,
      expapply: false,
      options: [], // 操作员列表
    };
  },
  methods: {
    onSubmit() {
      let timestart = null;
      let timeend = null;
      if (this.value == "") {
        console.log("submit!!!");
        this.$message.warning("请选择起止时间！");
      } else {
        var reg = /^((?:19|20)\d\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/;
        var regExp = new RegExp(reg);
        if (regExp.test(this.value[0]) && regExp.test(this.value[1])) {
          timestart = this.value[0];
          timeend = this.value[1];
        } else {
          timestart =
            this.value[0].getFullYear() +
            "-" +
            (this.value[0].getMonth() + 1) +
            "-" +
            this.value[0].getDate();
          timeend =
            this.value[1].getFullYear() +
            "-" +
            (this.value[1].getMonth() + 1) +
            "-" +
            this.value[1].getDate();
        }
        console.log(timestart); // 开始时间
        console.log(timeend); // 结束时间
        let data = {
          Startdate: timestart,
          Enddate: timeend,
          uid: this.state,
        };
        if (this.state == "") {
          data.uid = '0';
        }
        API_GET_USER_ADMIN(data)
          .then((res) => {
            console.log(res);
            this.tableData = res.ResList;
          })
          .catch((err) => {
            console.log(err);
          });
      }
      this.expapply = true;
    },
    query() {
      API_GET_OPERATOR_LIST()
        .then((res) => {
          console.log(res);
          this.options = res.ResList;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 默认时间
    nowTim() {
      this.value["0"] =
        new Date().getFullYear() +
        "-" +
        (new Date().getMonth() + 1 < 10
          ? "0" + (new Date().getMonth() + 1)
          : new Date().getMonth() + 1) +
        "-" +
        (new Date().getDate() < 10
          ? "0" + new Date().getDate()
          : new Date().getDate());
      this.value["1"] =
        new Date().getFullYear() +
        "-" +
        (new Date().getMonth() + 1 < 10
          ? "0" + (new Date().getMonth() + 1)
          : new Date().getMonth() + 1) +
        "-" +
        (new Date().getDate() < 10
          ? "0" + new Date().getDate()
          : new Date().getDate());
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pagesize = val;
    },
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage;
    },
    //     /* 导出文档 */
    // exportClick() {
    //   this.export2Excel();
    // },
    // export2Excel() {
    //   require.ensure([], () => {
    //     const { export_json_to_excel } = require("../../vendor/Export2Excel");

    //     const tHeader = [
    //       "编号",
    //       "操作员",
    //       "操作时间",
    //       "操作",
    //     ];

    //     const filterVal = [
    //       "number",
    //       "village",
    //       "landname",
    //       "years",
    //     ];

    //     const list = [
    //       {
    //         number: 1,
    //         village: "1村",
    //         landname: "第一项目",
    //         years: "2020",
    //       },
    //     ];

    //     const data = this.formatJson(filterVal, list);

    //     export_json_to_excel(tHeader, data, "**征地批文" + new Date());
    //   });
    // },
    // formatJson(filterVal, jsonData) {
    //   return jsonData.map((v) => filterVal.map((j) => v[j]));
    // },
    printText() {
      this.$router.push("/projectinfo/print");
    },
  },
  created() {
    this.query();
    this.nowTim();
    this.onSubmit();
  },
};
</script>

<style scoped lang="scss">
.operation {
  padding: 30px;
  .el-pagination {
    // max-width: 700px;
    margin-top: 10px;
    text-align: right;
  }
}
</style>
